﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Reporting.WinForms;

namespace Willson.JsbManager.UI
{
    public partial class XTPrintViewForm : Form
    {
        private PrintDataSet ds = null;
        private BindingSource bindingSource = null;
        private ReportDataSource reportDataSource = null;

        public XTPrintViewForm()
        {
            reportDataSource = new ReportDataSource();
            bindingSource = new BindingSource();

            InitializeComponent();
              
        }

        /// <summary>
        /// 数据源绑定
        /// </summary>
        /// <param name="ds">DataSet数据源</param>
        /// <param name="dataMember">绑定的表名</param>
        /// <param name="rdlc_name">报表文件</param>
        /// <param name="dataSourceName">报表数据源名</param>
        /// <param name="list">参数列表</param>
        public void Bind(PrintDataSet ds, string dataMember, string rdlc_name, string dataSourceName, List<ReportParameter> list)
        {
            this.ds = ds;
            
            this.bindingSource.DataMember = dataMember;
            this.bindingSource.DataSource = this.ds;
            this.reportDataSource.Name = dataSourceName;
            this.reportDataSource.Value = this.bindingSource;
            this.reportViewer.LocalReport.DataSources.Add(reportDataSource);
            this.reportViewer.LocalReport.ReportEmbeddedResource = rdlc_name;

            if (list != null)
                this.reportViewer.LocalReport.SetParameters(list);
        }

        private void XTPrintViewForm_Load(object sender, EventArgs e)
        {

            this.reportViewer.RefreshReport();
        }
    }
}
